package cn.bdqn.controller;

import cn.bdqn.domain.Overview;
import cn.bdqn.service.OverviewService;
import cn.bdqn.utils.result.Result;
import cn.bdqn.utils.result.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 概述控制层
 * @author dkj
 */
@RestController
@RequestMapping("/overview")
public class OverviewController {

    @Autowired
    private OverviewService overviewService;

    /**
     * 保存的方法
     * @param overview
     * @return
     */
    @RequestMapping("/saveOverview")
    public Result saveOverview(Overview overview) throws Exception{
        try {
            //调用保存方法
            overviewService.saveOverview(overview);
            //返回结果
            return ResultGenerator.genSuccessResult();
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }

    /**
     * 发布的方法
     * @param overview
     * @return
     */
    @RequestMapping("/releaseOverview")
    public Result releaseOverview(Overview overview) throws Exception{
        try {
            //调用发布的方法
            overviewService.releaseOverview(overview);
            //返回结果
            return ResultGenerator.genSuccessResult();
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }

    /**
     * 根据基地id和描述状态查询
     * @param baseId
     * @param descriptionType
     * @return
     */
    @RequestMapping("/queryByBaseIdAndDescriptionType")
    public Result queryByBaseIdAndDescriptionType(Integer baseId, Integer descriptionType)throws Exception{
        try {
            //根据基地id和发布描述类型查询
            Overview overview = overviewService.queryByBaseIdAndDescriptionType(baseId,descriptionType);
            //返回结果
            return ResultGenerator.genSuccessResult(overview);
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }
}
